<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class UserInsertRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'username' => 'required|regex:/^\w{6,20}$/|unique:users,username',
            'password' => 'required|regex:/^\S{6,20}$/|same:repassword',
            'email' =>'required|email'
        ];
    }
    public function messages()
    {
        return [
            'username.required'=>'对不起用户名必填',
            'username.regex'=>'用户名格式不正确',
            'username.unique'=>'用户名已经存在',
            'password.required' => '密码必填',
            'password.regex' => '密码格式不正确',
            'password.same' => '两次密码不一致',
            'email.email'=>'邮箱格式不正确',
            'email.required' => '邮箱不能为空'
        ];
    }    
}
